package com.ttai.ui.other;

import android.app.Dialog;
import android.content.ClipboardManager;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.squareup.picasso.Picasso;
import com.ttai.R;

import butterknife.OnClick;

public class DecryptDialog extends Dialog {

    Button fuzhinumber;
    Button fuzhipassword;
    ImageView ivicon;
    TextView tvMessgae;
    TextView tvAccountname;
    TextView tvAccountnumber;
    TextView tvPassword;

    private String message;
    private String accountname;
    private String accountnumber;
    private String password;
    private String imgUrl;


    public DecryptDialog(Context context) {
        super(context, R.style.MyDialog);
    }



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_decryt);
        //按空白处不能取消动画
        setCanceledOnTouchOutside(false);

        initView();

        initData();

        fuzhinumber.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                ClipboardManager cmb = (ClipboardManager) getContext().getSystemService(Context.CLIPBOARD_SERVICE);
                cmb.setText(tvAccountnumber.getText().toString().trim()); //将内容放入粘贴管理器,在别的地方长按选择"粘贴"即可
                Toast.makeText(getContext(), "复制账号成功", Toast.LENGTH_SHORT).show();
            }
        });

        fuzhipassword.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                ClipboardManager cmb1 = (ClipboardManager) getContext().getSystemService(Context.CLIPBOARD_SERVICE);
                cmb1.setText(tvPassword.getText().toString().trim()); //将内容放入粘贴管理器,在别的地方长按选择"粘贴"即可
                Toast.makeText(getContext(), "复制密码成功", Toast.LENGTH_SHORT).show();
            }
        });
    }

    private void initView() {
        tvMessgae = (TextView)findViewById(R.id.tv_messgae);
        tvAccountname = (TextView)findViewById(R.id.tv_accountname);
        tvAccountnumber = (TextView)findViewById(R.id.tv_accountnumber);
        tvPassword = (TextView)findViewById(R.id.tv_password);
        fuzhinumber = (Button)findViewById(R.id.btn_copyacount);
        fuzhipassword = (Button)findViewById(R.id.btn_copypassword);
        ivicon = (ImageView)findViewById(R.id.iv_icon);
    }

    private void initData() {
        //如果用户自定了title和message
//        if (message != null) {
//            tvMessgae.setText(message);
//        }
        if (accountname !=null){
            tvAccountname.setText(accountname);
        }
        if (accountnumber !=null){
            tvAccountnumber.setText(accountnumber);
        }
        if (password != null){
            tvPassword.setText(password);
        }
        if (imgUrl != null){
            Picasso.with(getContext()).load(imgUrl).placeholder(R.drawable.xike1).into(ivicon);
        }
    }

    public TextView getTvMessgae() {
        return tvMessgae;
    }


    public void setMessage(String message) {
        this.message = message;
    }

    public void setAccountname(String accountname) {
        this.accountname = accountname;
    }

    public void setAccountnumber(String accountnumber) {
        this.accountnumber = accountnumber;
    }

    public void setImgUrl(String imgUrl) {
        this.imgUrl = imgUrl;
    }

    public void setPassword(String password) {
        this.password = password;
    }



//    @OnClick({R.id.btn_copyacount, R.id.btn_copypassword})
//    public void onViewClicked(View view) {
//        switch (view.getId()) {
//            case R.id.btn_copyacount:
//                ClipboardManager cmb = (ClipboardManager) getContext().getSystemService(Context.CLIPBOARD_SERVICE);
//                cmb.setText(tvAccountnumber.getText().toString().trim()); //将内容放入粘贴管理器,在别的地方长按选择"粘贴"即可
//                Toast.makeText(getContext(), "复制账号成功", Toast.LENGTH_SHORT).show();
//                break;
//            case R.id.btn_copypassword:
//                ClipboardManager cmb1 = (ClipboardManager) getContext().getSystemService(Context.CLIPBOARD_SERVICE);
//                cmb1.setText(tvPassword.getText().toString().trim()); //将内容放入粘贴管理器,在别的地方长按选择"粘贴"即可
//                Toast.makeText(getContext(), "复制账号成功", Toast.LENGTH_SHORT).show();
//                break;
//        }
//    }
}
